﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IBS
{
    public partial class IbsDataContext
    {
        public IEnumerable<IBSImportFileFormat> GetIBSImport(long InvoiceID)
        {            
            var sql = String.Format(@"
                                      SELECT S.SITEIBSCODE,
                                             SO.DOC_NUMBER,
                                             SO.COMPANY_KEY,
                                             S.IP,
                                             SO.DOC_DATE,
                                             SUM (SOL.QUANTITY) QTY,
                                             SOL.ITEM_KEY,
                                             SOL.ACTUAL_PRICE
                                        FROM edex.WH_SALESORDER SO
                                             LEFT JOIN edex.WH_SALESORDERLINES SOL
                                                ON SO.ID_RECORD = SOL.ID_INVOICE
                                             LEFT JOIN IBSDBO.TBSITE S
                                                ON SO.LOCATION_KEY = S.SITEIBSCODE
                                        WHERE SO.ID_RECORD = {0}
                                    GROUP BY S.SITEIBSCODE,
                                             SO.DOC_NUMBER,
                                             SO.COMPANY_KEY,
                                             S.IP,
                                             SO.DOC_DATE,
                                             SOL.ITEM_KEY,
                                             SOL.ACTUAL_PRICE", InvoiceID);            

            return new DB
                .Oracle(this.connectionString)
                .Excecute<IBSImportFileFormat>(sql);


        }
    }
}
